﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WindowsFormsView;
using WindowsFormsModel.BusinessObjects;

namespace WindowsFormsPresenter.InwardOutward
{
    public class InwardOutwardPresenter : Presenter<IInwardOutwardView>
    {
        public InwardOutwardPresenter(IInwardOutwardView view)
            : base(view)
        {
        }

        public void Display(string refId)
        {
            if (refId == null) return;

            var inwardOutward = Model.GetInwardOutwardModel(refId);

            View.RefID = inwardOutward.RefID;
            View.RefType = inwardOutward.RefType;
            View.RefDate = inwardOutward.RefDate;
            View.PostedDate = inwardOutward.PostedDate;
            View.RefNo = inwardOutward.RefNo;
            View.EmployeeID = inwardOutward.EmployeeID;
            View.AccountingObjectID = inwardOutward.AccountingObjectID;
            View.AccountingObjectName = inwardOutward.AccountingObjectName;
            View.AccountingObjectAddress = inwardOutward.AccountingObjectAddress;
            View.JournalMemo = inwardOutward.JournalMemo;
            View.CurrencyID = inwardOutward.CurrencyID;
            View.ExchangeRate = inwardOutward.ExchangeRate;
            View.IsImportPurchase = inwardOutward.IsImportPurchase;
            View.ShippingMethodID = inwardOutward.ShippingMethodID;
            View.TotalAmount = inwardOutward.TotalAmount;
            View.RestaurantID = inwardOutward.RestaurantID;
            View.IsPosted = inwardOutward.IsPosted;
            View.IsMaterial = inwardOutward.IsMaterial;
            View.InwardOutwardDetails = inwardOutward.InwardOutwardDetails;
        }

        public int Save(string refTypeName)
        {
            var inwardOutward = new InwardOutwardModel
            {
                RefID = View.RefID,
                RefType = View.RefType,
                RefDate = View.RefDate,
                PostedDate = View.PostedDate,
                RefNo = View.RefNo,
                EmployeeID = View.EmployeeID,
                AccountingObjectID = View.AccountingObjectID,
                AccountingObjectName = View.AccountingObjectName,
                AccountingObjectAddress = View.AccountingObjectAddress,
                JournalMemo = View.JournalMemo,
                CurrencyID = View.CurrencyID,
                ExchangeRate = View.ExchangeRate,
                IsImportPurchase = View.IsImportPurchase,
                ShippingMethodID = View.ShippingMethodID,
                TotalAmount = View.TotalAmount,
                RestaurantID = View.RestaurantID,
                IsPosted = View.IsPosted,
                IsMaterial = View.IsMaterial,
                InwardOutwardDetails = View.InwardOutwardDetails,
            };

            if (View.RefID == null)
                return Model.AddInwardOutward(inwardOutward, refTypeName);
            else
                return Model.UpdateInwardOutward(inwardOutward, refTypeName);
        }

        //public int Delete(string menuNormId)
        //{
        //    //return Model.DeleteRestaurantMenuNorm(menuNormId);
        //}
    }
}
